<!-- 供应商列表 -->
<template>
	<div class="supplier-manange-list" v-loading="state.loading">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form class="text-right" :model="state.queryParams" ref="queryForm" :inline="true">
				<!-- <el-form-item label="公司名称">
					<el-input v-model="state.queryParams.aaa" placeholder="请输入"/>
				</el-form-item>
				<el-form-item label="统一社会信用代码">
					<el-input v-model="state.queryParams.aaa" placeholder="请输入"/>
				</el-form-item>
				<el-form-item>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询 </el-button>
						<el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
					</el-button-group>
				</el-form-item> -->
				<el-form-item>
					<el-button type="primary" icon="ele-Plus" @click="showAdd()"> 新增 </el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card class="full-table" shadow="hover" style="margin-top: 8px">
			<el-table :data="state.list" style="width: 100%" border>
				<el-table-column type="index" label="序号" width="55" align="center" />
				<el-table-column prop="companyName" label="公司名称" align="center" show-overflow-tooltip />
				<el-table-column prop="unifiedSocialCode" label="统一社会信用代码" align="center" show-overflow-tooltip />
				<el-table-column prop="city" label="地址" align="center" show-overflow-tooltip />
				<!-- <el-table-column prop="aaa" label="联系方式" align="center" show-overflow-tooltip /> -->
				<el-table-column prop="companyType" label="企业类别" width="80" align="center" show-overflow-tooltip>
					<template #default="scope">
						{{getLabelByValue( state.companyTypeList, scope.row.companyType, '', 'value', 'code')}}
					</template>
				</el-table-column>
				<el-table-column prop="scope" label="主营内容" align="center" show-overflow-tooltip />
				<!-- <el-table-column prop="aa7" label="关联项目" width="80" align="center" show-overflow-tooltip /> -->
				<el-table-column prop="createrName" label="创建人" align="center" show-overflow-tooltip />
				<el-table-column label="操作" width="150" align="center" fixed="right" show-overflow-tooltip>
					<template #default="scope">
						<el-button icon="el-icon-edit" size="small" text type="primary" @click="showAdd(scope.row)">编辑</el-button>
						<el-button icon="el-icon-delete" size="small" text type="primary" @click="deleteRow(scope.row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-card>

		<addModal ref="addModalRef" @reload="handleQuery"></addModal>
	</div>
</template>

<script setup name="SupplierManage">
import { onMounted, reactive, ref } from 'vue';
import {useRouter, useRoute} from "vue-router";
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
import {$get, $post} from '/@/utils/request';
import addModal from "./modules/addModal.vue";
import {getLabelByValue} from "/@/utils/Tools.js";

const router = useRouter();
const route = useRoute();
const addModalRef = ref();

const PUBLIC_PATH = import.meta.env.VITE_PUBLIC_PATH;
const state = reactive({
	loading: false,
	queryParams: {
		aaa: '',
		bbb: '',
	},
	list: [],
	tableParams: {
		page: 1,
		pageSize: 20,
		total: 0,
	},

	companyTypeList: [],
});

onMounted(async () => {
	handleQuery();
	// 获取企业类别列表
	getCompanyType();
});

// 查询操作
const handleQuery = async () => {
	state.loading = true;
	var res = await $post('/providerSrv/getprovider/0');
	state.list = res.result || [];
	state.loading = false;
};

// 重置操作
const resetQuery = () => {
	state.queryParams.aaa = '';
	state.queryParams.bbb = '';
	handleQuery();
};

// 获取企业类别列表
const getCompanyType = () => {
	$get('/sysDictData/dataList?code=company_type').then(res => {
		state.companyTypeList = res.result;
	})
}

// 新增
const showAdd = (row) => {
	addModalRef.value.open(row);
}

// 删除
const deleteRow = row => {
	ElMessageBox.confirm('此操作将删除该供应商，是否继续？', '提示', {
		type: 'warning'
	}).then(async () => {
		var res = await $post('/providerSrv/removeproider/'+row.id);
		ElNotification({
	    title: '提示',
	    message: '删除成功',
	    type: 'success',
	  })
	  // 更新列表
	  handleQuery();
	})
}

// 显示数据源
const showResource = (row) => {
	resourceModalRef.value.open(row.datasource);
};

</script>

<style lang="scss" scoped>
.supplier-manange-list {
	
}
</style>
